home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / controls / seltext.frm < prev    next >
Text File  |  1993-05-16  |  3KB  |  113 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Programatically Working With Selected Text"
  4.    ClientHeight    =   4020
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   7365
  8.    Height          =   4425
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4020
  12.    ScaleWidth      =   7365
  13.    Top             =   1140
  14.    Width           =   7485
  15.    Begin CommandButton Command3 
  16.       Caption         =   "Replace It!"
  17.       Height          =   500
  18.       Left            =   5400
  19.       TabIndex        =   5
  20.       Top             =   2040
  21.       Width           =   1455
  22.    End
  23.    Begin TextBox Text2 
  24.       Height          =   380
  25.       Left            =   5400
  26.       TabIndex        =   3
  27.       Top             =   1200
  28.       Width           =   1455
  29.    End
  30.    Begin CommandButton Command2 
  31.       Caption         =   "End"
  32.       Height          =   500
  33.       Left            =   5400
  34.       TabIndex        =   2
  35.       Top             =   3000
  36.       Width           =   1455
  37.    End
  38.    Begin CommandButton Command1 
  39.       Caption         =   "Next Word"
  40.       Height          =   500
  41.       Left            =   5400
  42.       TabIndex        =   1
  43.       Top             =   240
  44.       Width           =   1455
  45.    End
  46.    Begin TextBox Text1 
  47.       Height          =   3260
  48.       HideSelection   =   0   'False
  49.       Left            =   240
  50.       MultiLine       =   -1  'True
  51.       TabIndex        =   0
  52.       Top             =   240
  53.       Width           =   4695
  54.    End
  55.    Begin Label Label1 
  56.       Caption         =   "Replacement"
  57.       Height          =   260
  58.       Left            =   5400
  59.       TabIndex        =   4
  60.       Top             =   960
  61.       Width           =   1335
  62.    End
  63. End
  64. Option Explicit
  65.  
  66. Sub Command1_Click ()
  67.     Static NotFirstTime As Integer
  68.     Static PosSpace As Integer
  69.     
  70. TryAgain:
  71.     If NotFirstTime Then
  72.         Text1.SelStart = PosSpace
  73.         PosSpace = PosSpace + 1
  74.         PosSpace = InStr(PosSpace, Text1.Text, " ")
  75.         If PosSpace = 0 Then
  76.             Exit Sub
  77.         End If
  78.         Text1.SelLength = (PosSpace - 1) - Text1.SelStart
  79.         If Text1.SelLength = 0 Then
  80.             GoTo TryAgain
  81.         End If
  82.     Else
  83.         NotFirstTime = True
  84.         Text1.SelStart = 0
  85.         PosSpace = InStr(Text1.Text, " ")
  86.         Text1.SelLength = PosSpace - 1
  87.     End If
  88.  
  89. End Sub
  90.  
  91. Sub Command2_Click ()
  92.     End
  93. End Sub
  94.  
  95. Sub Command3_Click ()
  96.     Text1.SelText = Text2.Text
  97.     Command1.SetFocus
  98. End Sub
  99.  
  100. Sub Form_Load ()
  101.     Dim fhandle As Integer
  102.     Dim fname As String
  103.  
  104.     fhandle = FreeFile
  105.     fname = "c:\vbdemos\controls\inferno.txt"
  106.     Open fname For Input As fhandle
  107.  
  108.     Text1.Text = Input(LOF(fhandle), fhandle)
  109.     Close fhandle
  110.  
  111. End Sub
  112.  
  113.